import Common from '../../common/common.js';
import BaseListItem from '../base/BaseListItem.js';
import {UpdateGroupWin} from './GroupWin.js';
import TimNet from '../../timnet.js';
import Talk from "../conversation/Talk.js";

//寄生组合式继承
function GroupListItem (data) {
    BaseListItem.call(this,data);
    this.setData(data);
 }
let prototype = Object.create(BaseListItem.prototype);
prototype.constructor = GroupListItem;
GroupListItem.prototype  = prototype;

//操作数据
GroupListItem.prototype.initHandleData = function () {
    return [{label:"span",tag:"del",props:{className:"del"}}]
}

//设置数据
GroupListItem.prototype.setData = function(data){
    this.data = data;
    this.setAvatar(Common.tool.getAvatar(data.avatar));
    this.setName(data.name);
    this.setMsg(data.introduction);
}

//各个操作事件
GroupListItem.prototype.bind = function(){

    Common.tool.addHandle(this.element.avatarDiv,"click",()=>{
       //打开群信息
        new UpdateGroupWin(this.data).open();
    });

    Common.tool.addHandle(this.element.handle.del,"click",()=>{
        if(window.confirm("确定要退出此群组?")){
            TimNet.quitGroup(this.data.groupID);
        }
    });

    Common.tool.addHandle(this.element.infoDiv,"click",()=>{

        Talk.openByID("GROUP"+this.data.groupID);
    });

}

export default GroupListItem
